﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
using YJKArchCriterion;

namespace YJKRevitStairs.StairsModel.DataInfos
{
	public class FormParamManager
	{
		public static double GetStairsHeight(double dLevelValue, double dTopOffset, double dBottomOffset)
		{
			return dLevelValue + dTopOffset - dBottomOffset;
		}

		public static int GetStairsTreadCount(double dStairsHeight, double dTreadHeight)
		{
			return (int)Math.Round(dStairsHeight / dTreadHeight, 0);
		}

		public static string GetAppRootPath()
		{
			string location = Assembly.GetExecutingAssembly().Location;
			int length = location.LastIndexOf("\\");
			string text = location.Substring(0, length);
			length = text.LastIndexOf("\\");
			return text.Substring(0, length);
		}

		public static string GetArchStdXmlPath()
		{
			return FormParamManager.GetAppRootPath() + "\\Data\\建筑规范.xml";
		}

		public static string GetStairsFamiliyPath(string sRvtVersion = "2014")
		{
			return FormParamManager.GetAppRootPath() + "\\FamilyLib\\Family\\" + sRvtVersion + "\\Stairs\\";
		}

		public static int GetRunMinTread()
		{
			return 3;
		}

		public static int GetRunMaxTread()
		{
			return 18;
		}

		public static string GetValidatingData(List<ValidatingData> listValidatingData, string UsingRange, double dRunWdith)
		{
			string text = null;
			string archStdXmlPath = FormParamManager.GetArchStdXmlPath();
			StairArchStd instance = StairArchStd.GetInstance("08BJ7-1", archStdXmlPath);
			foreach (ValidatingData validatingData in listValidatingData)
			{
				string str = null;
				switch (validatingData.Type)
				{
				case DataType.DT_RunWidth:
					if (!instance.CheckStairsRunWidth(UsingRange, validatingData.Value, ref str))
					{
						text = text + validatingData.Name + str + "\n";
					}
					break;
				case DataType.DT_TreadHeight:
					if (!instance.CheckStairTreadHeight(UsingRange, validatingData.Value, ref str))
					{
						text = text + validatingData.Name + str + "\n";
					}
					break;
				case DataType.DT_TreadDepth:
					if (!instance.CheckStairTreadDepth(UsingRange, validatingData.Value, ref str))
					{
						text = text + validatingData.Name + str + "\n";
					}
					break;
				case DataType.DT_LandWidth:
					if (!instance.CheckStairsLandWidth(UsingRange, validatingData.Value, dRunWdith, ref str))
					{
						text = text + validatingData.Name + str + "\n";
					}
					break;
				case DataType.DT_TreadCount:
					if (!instance.CheckStairsSingleRunTreadNum((double)validatingData.Count, ref str))
					{
						text = text + validatingData.Name + str + "\n";
					}
					break;
				case DataType.DT_LadderHeight:
					if (!instance.CheckStairLadderHeight(UsingRange, validatingData.Value, ref str))
					{
						text = text + validatingData.Name + str + "\n";
					}
					break;
				case DataType.DT_LandHeight:
					if (!instance.CheckStairLandHeight(UsingRange, validatingData.Value, ref str, 0))
					{
						text = text + validatingData.Name + str + "\n";
					}
					break;
				}
			}
			return text;
		}

		public static void MessageBoxWarning(string strTip)
		{
			MessageBox.Show(strTip, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
		}

		public static int m_nRunMinTreadCount = 3;

		public static string m_strRunMinTreadChkTip = "梯段踏步数不应少于3级.";
	}
}
